package efu.nf.like.web.controller;

import efu.nf.like.common.base.BaseController;
import efu.nf.like.common.result.ResultVo;
import efu.nf.like.model.entity.User;
import efu.nf.like.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author lwj
 * @create 2025-10-12-19:26
 */
@RestController
@RequestMapping("/api/user")
@RequiredArgsConstructor
public class UserController extends BaseController {
    private final UserService userService;

    @GetMapping("/byName/{username}")
    public ResultVo<User> selectByUserName(@PathVariable String username) {
        User user = userService.selectByUserName(username);
        return success(user);
    }

    @PostMapping()
    public<T> ResultVo<T> insert(@RequestBody User user) {
        userService.insert(user);
        return success();
    }

    @PutMapping()
    public<T> ResultVo<T> update(@RequestBody User user) {
        userService.update(user);
        return success();
    }

    @DeleteMapping("/{userId}")
    public<T> ResultVo<T> delete(@PathVariable Integer userId) {
        userService.delete(userId);
        return success();
    }
}